package com.example.JcGQS.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * mybatis +填充配置
 *
 * @author 末日
 * @date 2023/7/13
 */
@Component
public class MybatisPlusFillConfig implements MetaObjectHandler {
    /**
     * 插入元对象字段填充（用于插入时对公共字段的填充）
     *
     * @param metaObject 元对象
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "dataCreateTime", LocalDateTime::now,
                              LocalDateTime.class);
        this.strictUpdateFill(metaObject, "dataUpdateTime", LocalDateTime::now,
                              LocalDateTime.class);
    }

    /**
     * 更新元对象字段填充（用于更新时对公共字段的填充）
     *
     * @param metaObject 元对象
     */
    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject, "dataUpdateTime", LocalDateTime::now,
                              LocalDateTime.class);
    }
}
